<?php



namespace App\Models\Traits;


/**
 *
 * @author Administrator
 */
trait HasDevice {
    
    protected static function bootHasDevice()
    {

		static::updating(function ($model) {
			$data = static::getCompanyData();
			$model->fill($data);
        });
		
		static::creating(function ($model) {
			$data = static::getCompanyData();
			$model->fill($data);
        });
		
		static::updated(function ($model) {

        });
		
		static::created(function ($model) {

        });
		
		static::deleted(function ($model) {
            if (method_exists($model, 'isForceDeleting') && ! $model->isForceDeleting()) {
                return;
            }
			
        });
		
    }
	
	protected static function getCompanyData() {
		//$user = $request->user();
		$data = app('request')->only('Co_ID');
		$user = auth()->user();
		$isSuper = $user->isSuper();

		if (!$isSuper) {
			$data['Co_ID'] = $user->Co_ID;
		}
		$data['pdi_updatetime'] = date('Y-m-d H:i:s');
		return $data;
	}
}
